/*Copyright (C) 2013-2022 LZE*/
#include<bits/stdc++.h>
#define fo(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
#define INF 0x7fffffff
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int N = 6000000;
const int M = 6000000;
ll T,n,m;
struct TreeEdge{
    ll to,next,w;
    TreeEdge(){}
}edge[M];
ll head[N] = {0},cnt = 0;
void add(ll u,ll v,ll w){
    edge[++cnt].to = v;
    edge[cnt].w = w;
    edge[cnt].next = head[u];
    head[u] = cnt;
}
ll dis_f[N] = {0},dis_s[N] = {0};
ll maxn = 0;
void dfs(ll father,ll step){
    for(ll i = head[step];i;i = edge[i].next){
        if(edge[i].to != father){
            dfs(step,edge[i].to);
            ll tmp = dis_f[edge[i].to] + edge[i].w;
            if(dis_f[step] < tmp){
                dis_s[step] = dis_f[step];
                dis_f[step] = tmp;
            }
            else if(dis_s[step] < tmp)dis_s[step] = tmp;
        }
    }
    maxn = max(maxn,dis_f[step] + dis_s[step]);
}
int main(){
    scanf("%lld",&n);
    ll u,v,w;
    for(ll i = 1;i < n;i++){
        scanf("%lld%lld%lld",&u,&v,&w);
        add(u,v,w);
        add(v,u,w);
    }
    dfs(0,1);
    printf("%lld\n",maxn);
    return 0;
}
